home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-07 | 2.6 KB | 95 lines | [TEXT/ttxt] |
- OpenDoc™ Recipes
-
- Iterators
- By The OpenDoc Design Team
- November, 1995
-
-
- © 1993-1995 Apple Computer, Inc. All Rights Reserved.
- Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
- Mac and OpenDoc are trademarks of Apple Computer, Inc.
-
-
- Introduction
-
- The OpenDoc interfaces used by part developers include several iterators:
-
- ODObjectIterator (NameSpace)
- ODValueIterator (Name Space)
- ODFacetIterator
- ODFrameFacetIterator
- ODDragItemIterator
- ODLinkIterator
- ODLinkSourceIterator
- ODPlatformTypeListIterator
- ODTypeListIterator
- ODFocusSetIterator
- ODWindowIterator
-
- Part developers must also provide one iterator themselves, a subclass of:
-
- ODEmbeddedFramesIterator
-
- Developers of non-exclusive focus modules must also provide a subclass of:
-
- ODFocusOwnerIterator
-
- Interfaces
-
- All of these iterators have at least the following three methods:
-
- First() - begins the iteration and returns the first element
- Next() - returns the next element
- IsNotComplete() - returns true if there are more elements
-
- Some of the iterators also have Last() and Previous() methods.
- Most iterators return values as the result of the First and Next methods
-
- Usage
-
- Iterators can be used in the following ways:
-
- ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
- for (ODFacet* facet = iter->First(ev); iter->IsNotComplete(ev);
- facet = iter->Next(ev))
- {
-
- }
-
- or the equivalent:
-
- ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
- ODFacet* facet = iter->First()
- while (iter->IsNotComplete())
- {
- …
- facet = iter->Next(ev);
- }
-
- or, if there is a well-defined NULL value for the elements:
-
- ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
- while ((facet = iter->Next(ev)) != kODNULL)
- {
- }
-
-
- Rules
-
- • First() means both "start iteration" and "give me an item"
- • Next() means "give me the next item"
- • IsNotComplete() returns true if there are more items.
-
- • If Next() is called before First(), it means First().
- • IsNotComplete() will throw an error (kODErrIteratorNotInitialized) if neither First() nor Next() has been called.
-
- • If an iterator is bidirectional, the direction is an invariant. Once the iteration has begun, you can't change directions.
- • For an empty collection, First() and Next() return the NULL value if there is one. IsNotComplete() returns kODFalse.
-
- • If IsNotComplete() returns kODTrue, the last item obtained is valid.
- • If IsNotComplete() returns kODFalse (at the end of the iteration), Next() will return the NULL value, if there is one.
-
- • If the underlying collection is modified while an iteration is in progress, the iterator methods will throw an exception (kODErrIteratorOutOfSync).
-
-
-